<?
include ('../../sessions.php');
include ('../../variables.php');
include('functions.php');
//include('functions.php');
$webDIR="admin";
include("../session_check.php");
if (getenv(REQUEST_METHOD) == "GET") {
	switch($action) {
		case "view":
			$fileTemplate="view_upcomming.html";
			include("../main.html");
		break;
		case "view_detailed":
			$fileTemplate="view_detailed.html";
			include("../main.html");
		break;
		case "history":
			$fileTemplate="history.html";
			include("../main.html");
		break;
		case "groups":
			$fileTemplate="payment_groups.html";
			include("../main.html");
		break;
		
        case "view_groups":
            $fileTemplate="view_affiliates.html";
            include("../main.html");
        break;
		case "print_page":
			include("print_page.html");
		break;
		case "print_checks":
			include("print_checks.html");
		break;
		case "us_stats":
			$fileTemplate="us_stats.html";
			include("../main.html");
		break;
		case "mainPanel":
			$fileTemplate="mainPanel.html";
			include("../main.html");
		
		break;
		case "paypal_email":
			$fileTemplate='pp_email_change.html';
			include("../main.html");

		break;
	}
}else if(getenv(REQUEST_METHOD) == "POST"){
	switch($action){
		case "approve_payment":
			$sales=$HTTP_POST_VARS[sales];
			$comment=$HTTP_POST_VARS[comment];
			$payment_method=$HTTP_POST_VARS[payment_method];
	
			$amount=$HTTP_POST_VARS[amount];
			$res_id=$HTTP_POST_VARS[res_id];			
			if ($payment_method=='wallet') {
				 if(!approve_payment_wallet($res_id,$amount,$sales,$comment,$payment_method)){ $errorCode=0; $errorMsg=" Error #2. Please contact the support "; $fileTemplate= 'view_detailed.html'; include('../main.html');exit();}
			exit("Transactions have been approved successfully");
			} else {
				if(!approve_payment($res_id,$amount,$sales,$comment,$payment_method)){ $errorCode=0; $errorMsg=" Error #2. Please contact the support "; $fileTemplate= 'view_detailed.html'; include('../main.html');exit();}
			exit("Transactions have been approved successfully");
			}
			exit_now();
		break;
		case "history":
			$year=$_POST[year];
			$month=$_POST[month];
			$fileTemplate="history.html";
			include("../main.html");
		break;
		
                case "view_groups":
                        $subaction=$_POST[subaction];
                        $type=$_POST[type];
                        $parent_id=$_POST[parent_id];
                        $child_id=$_POST[child_id];
                        $res_id=$parent_id;
                        switch($subaction){
                                case "add":
                                        $res=add_group_member($type,$parent_id,$child_id);
                                break;
                                case "remove":
                                        $res=remove_group_member($type,$parent_id,$child_id);
                                break;

                        }
                        if(!$res) { $errorCode=0; $errorMsg=" Error #2. Duplicate entries "; $fileTemplate= 'view_affiliates.html'; include('../main.html');exit();}
                        $fileTemplate= 'view_affiliates.html'; include('../main.html');exit();

                break;
		case "paypal_email":

			$pp_email=$_POST[pp_email];
			if(!change_pp_email($res_id,$pp_email)) exit('ERROR');
			$fileTemplate='pp_email_change.html';
			include("../main.html");

		break;
		default:
			$fileTemplate="mainPanel.html";
			include("../main.html");        	       	
		break;

        }
}
?>
